package com.example.back.exception;

import com.example.back.common.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Jm
 * @date 2024/7/13
 */
@ControllerAdvice
public class GlobalException
{
    @ExceptionHandler(ServiceException.class)
    @ResponseBody
    public Result serviceException(ServiceException e)
    {
        return Result.error(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result globalException(Exception e)
    {
        e.printStackTrace();
        return Result.error("500", "系统错误");
    }
}
